﻿             <link href="@Url.Content("~/content/activitie_detail.css")" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="@Url.Content("~/plugin/css/pikaday.css")">
<link rel="stylesheet" href="@Url.Content("~/plugin/css/site.css")">
<script src="@Url.Content("~/plugin/moment.min.js")"></script>
<script src="@Url.Content("~/plugin/pikaday.js")"></script>

@model PessMvc.Models.ArchivesModel

@{
    ViewBag.Title = "档案列表";

    bool hideArchiveDetails = false;
    hideArchiveDetails = Roles.IsUserInRole("ExpertJudge")
        && ViewBag.HideArchiveDetails != null
        && ViewBag.HideArchiveDetails == true;

    bool isAuthor = false;
    isAuthor = Roles.IsUserInRole(Membership.GetUser().UserName, "Author");

    bool isScheduledDateEnabled = ViewBag.IsScheduledDateEnabled;

    bool isExpertJudge= Roles.IsUserInRole(Membership.GetUser().UserName, "ExpertJudge");
}
@*@Html.Partial("_ActivityNavPartial",ViewData["ActivityID"])*@
@{
    string status = "";
    if (Roles.IsUserInRole("ExpertJudge")) {
        status = string.Format("（已评：{0}  /  总数：{1}）", Model.ReviewHistory.Count, Model.PageInfo.TotalItems);        
    }
}
@{
    IEnumerable<PessModel.Archive> archives = Model.All;

}
<div id="m-title">
    <h2>档案及评分</h2><span style="font-size:12px;"> @status</span>
        <div id="m-op">
            <span class="u-uf-show ie-11">
                @if(!Roles.IsUserInRole(Membership.GetUser().UserName, "Author"))
                {
                    using (Html.BeginForm("Index", "Archive", FormMethod.Get))
                    {
                        @Html.Hidden("ActivityID", ViewData["ActivityID"])
                        @Html.TextBox("KeyWord", null, null, new { @class = "u-it" })
                        <input type="submit" value="搜索" class="u-btn" />
                    }
                }
            </span>
            @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || 
                Roles.IsUserInRole(Membership.GetUser().UserName, "CountyAdmin") ||
                Roles.IsUserInRole(Membership.GetUser().UserName, "Author"))
            {
                if ((bool)ViewBag.IsArchiveModificationAllowed == true)
                {
                    <span class="u-uf-show ie-13">
                        @Html.ActionLink("新建", "Create", new { activityID = ViewData["ActivityID"] }, new { @class = "u-btn" })
                    </span>
                }
                if (Roles.IsUserInRole("Admin"))
                {
                    <span class="u-uf-show ie-12">
                        @using (Html.BeginForm("ImportReviewFeedbacks", "Archive", FormMethod.Post))
                        {
                            @Html.DropDownList("SubjectID")
                            <input type="submit" value="导入评审意见" class="u-btn f-btn-long" id="fly-btn" name="fly-btn" />
                        }
                    </span>
                    <span>
                       @Html.ActionLink("批量导入","AddArchives",new { activityID = Model.ActivityID }, new { @class = "u-btn" })                       
                    </span>
                }
            }

            @if (!hideArchiveDetails && !Roles.IsUserInRole(Membership.GetUser().UserName, "Author"))
            {
                <span class="u-uf-show ie-14">@Html.ActionLink("导出档案清单", "ExportArchiveList", "Archive", new { activityID = ViewData["ActivityID"] }, new { @class = "u-btn f-btn-long" })</span>
            }
        </div>
</div>
@if (Roles.IsUserInRole("ExpertJudge")&&Model.IsGradeRulesEnabled==true)
{
    @Html.Partial("_GradeHistoryPartial", Model.GradeHistory);
    if (!Model.IsVerificationCompleted)
    {
        @Html.ActionLink(" 确认完成 ", "VerifyGradeRules", "GradeRuleVerification", new { activityID = Model.ActivityID }, new { @class = "u-btn" })
        <p>&nbsp;</p>
    }
    else
    {
        <label>评分已经提交，不可再修改！</label>
    }
}
    @*<p>
         @Html.DisplayFor(model => Model.SingleOrDefault().Subject.Activity.Name)
        </p>*@


    @using(@Html.BeginForm("","Archive",FormMethod.Post)){
        <table id="fileList" class="oddTable">
            <tr>
                <th>□ </th>
                <th class="thTitle">
                    @*@PessResources.Archive.ProjectTitle*@
                @*@Model.ArchiveProjectTitleDisplayName*@                
                @Html.DisplayNameFor(model=>archives.FirstOrDefault().ProjectTitle)
            </th>
            <th class="thSName">
                @*@PessResources.Archive.SerialNumber*@
                @*@Model.ArchiveSerialNumberDisplayName*@
                @Html.DisplayNameFor(model => archives.FirstOrDefault().SerialNumber)            
            </th>
            <th class="thSName">
                @*@PessResources.Archive.SubjectName*@
                @*@Model.ArchiveSubjectNameDisplayName*@
                @Html.DisplayNameFor(model => archives.FirstOrDefault().Subject)
            </th>
            <th class="thCName">
                @*@PessResources.Archive.CountyName*@
                @*@Model.ArchiveCountyNameDisplayName*@
                @Html.DisplayNameFor(model => archives.FirstOrDefault().County)
            </th>
            <th class="thTName">
                @*@PessResources.Archive.TeacherName*@
                @*@Model.ArchiveTeacherNameDisplayName*@
                @Html.DisplayNameFor(model => archives.FirstOrDefault().TeacherName)
            </th>
            @*<th class="thLevel">
               @PessResources.Archive.GradeLevel
            </th>*@
            <th class="thSCName">
                @*@PessResources.Archive.SchoolName*@
                @*@Model.ArchiveSchoolNameDisplayName*@
                @Html.DisplayNameFor(model => archives.FirstOrDefault().SchoolName)
            </th>            
            @if (isScheduledDateEnabled)
            {
                <th>
                    @Html.DisplayNameFor(model => archives.FirstOrDefault().ScheduledDate)
                </th>
            }
            @if(!isAuthor)
            {
            <th style="width:65px">
                评委组
            </th>
            }
            @if (isExpertJudge)
            {
                <th>
                    分数
                </th>
                @*Consider to put a switch at here.*@
                <th> 
                    等第
                </th>
            }

            <th class="thAction" style="width:110px"></th>
        </tr>
    @{int x = 0;}
    @foreach (var item in Model.All)
            {
        <tr>
            <td class="f-ck-mid u-chk-th">@Html.CheckBox("Archives[" + x + "].IsSelected")
                @Html.Hidden("Archives[" + x + "].ArchiveID", item.ID)
            </td>
            <td class="thTitle">
                @Html.DisplayFor(modelItem => item.ProjectTitle)
            </td>
            <td class="thSName">
                @Html.DisplayFor(modelItem => item.SerialNumber)
            </td>
            <td class="thSName">
                @Html.DisplayFor(modelItem => item.Subject.Name)
            </td>
            <td class="thCName">
                @if (!hideArchiveDetails)
            {
                @Html.DisplayFor(modelItem => item.County.Name)
                }
            </td>
            <td class="thTName">
                @if (!hideArchiveDetails)
            {
                @Html.DisplayFor(modelItem => item.TeacherName)
                }
            </td>
            @*<td class="thLevel">
                @Html.DisplayFor(modelItem => item.GradeLevel)
            </td>*@
            <td class="thSCName">
                @if (!hideArchiveDetails)
                {
                    @Html.DisplayFor(modelItem => item.SchoolName)
                }
            </td>
            @if (isScheduledDateEnabled)
            {
            <td>
                @Html.DisplayFor(modelItem => item.ScheduledDate)
            </td>    
            }
            @if (!isAuthor)
            {
            <td>
                @if (!hideArchiveDetails)
                {
                    if (item.ExpertGroup != null)
                    {@item.ExpertGroup.Callsign}                
                }
            </td>
            }
            @*Showing Expert Score*@
            @if(isExpertJudge) 
            {
                <td>@Html.DisplayFor(modelItem =>Model.ArchiveScores.Find(s=>s.ArchiveID==item.ID).Score)</td>
            }
            @if(isExpertJudge)
            {
                <td>@Html.DisplayFor(modelItem=>Model.ArchiveGrades.Find(g=>g.ArchiveID==item.ID).GradeRuleName )</td>
            }
            <td class="thAction">
            @{bool showDelete = false, showDetails = false;}
            @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin"))
            {
                showDelete = true; showDetails = true;
            }
            else if (Roles.IsUserInRole(Membership.GetUser().UserName, "CountyAdmin"))
            {
                showDetails = true;
                if (ViewBag.IsArchiveModificationAllowed) { showDelete = true; }
            }
            else if (Roles.IsUserInRole(Membership.GetUser().UserName, "Author"))
            {
                showDetails = true;
                if (ViewBag.IsArchiveModificationAllowed) { showDelete = true; }
            }
            @if (showDelete)
            {
                @Html.ActionLink("删除", "Delete", new { id = item.ID })
            }
            @if (showDetails)
            {
                @Html.ActionLink("详细", "Details", new { id = item.ID }) 
            }
            @if (Roles.IsUserInRole(Membership.GetUser().UserName, "ExpertJudge"))
            {
                if (ViewBag.IsScoreInputAllowed)
                {
                    @Html.ActionLink("评分", "Grade", new { archiveID = item.ID, page=Model.PageInfo.CurrentPage })
                }
                if (Model.ReviewHistory.Select(r => r.ArchiveID).Contains(item.ID))
                { @Html.Label("已评", new { @class = "f-graded" })}
                else
                {
                    @Html.Label("未评", new { @class = "f-grade" })
                }
            }
            </td>
        </tr>
            { x = x + 1; }
    }

    </table>
                if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin"))
                {
        <div style="padding-top:20px">    <span>将档案分配到评委组：</span>

            @Html.DropDownList("ExpertGroupID", new SelectList(Model.ExpertGroups, "ID", "Callsign"))

            @Html.Hidden("Page", Model.PageInfo.CurrentPage)
            <input type="submit" value="分配" name="action:SetExpertGroup" class="u-btn" />
        </div>
                }
                if (isScheduledDateEnabled&& Roles.IsUserInRole(Membership.GetUser().UserName, "Admin")
                    || (Roles.IsUserInRole(Membership.GetUser().UserName, "CountyAdmin")
                    && ViewBag.IsChangeScheduledTimeAllowed))
                {
                    <div style="padding-top:20px">

                        <span>
                            @Html.DisplayNameFor(model => Model.All.FirstOrDefault().ScheduledDate)：
                            @Html.Hidden("activityID", Model.ActivityID)
                            @Html.TextBox("scheduledDate", null, null, new { @class = "u-it u-it-short" })
                            <input type="submit" value="设置" name="action:SetScheduledDate" class="u-btn" />
                        </span>
                    </div>
                }
                if (ViewBag.IsChangeScheduledTimeAllowed)
                {
                    <div style="padding-top:20px;">
                         <span>上课时间：</span>
                        @Html.Hidden("activityID", Model.ActivityID)
                        @Html.DropDownList("hours", Utility.HoursorMinutes(24),new { style="width:45px;"}) : @Html.DropDownList("minutes", Utility.HoursorMinutes(60), new { style = "width:45px;" })
                        <input type="submit" value="设置" name="action:SetScheduledTime" class="u-btn" />
                    </div>
                }
                }

<div id="pageNum" style="text-align:center !important;">@Html.PageLinks(Model.PageInfo,u=>Url.Action("Index","Archive",new {ActivityID=Model.ActivityID,SubjectID=Model.SubjectID,Keyword=Model.Keyword,Page=u}))</div>

<script language="javascript">
  //  var l = document.getElementById("fly-btn");
    //alert(document.getElementById("SubjectID").options.length)
  //  if (document.getElementById("SubjectID").options.length == 0) {
   //     l.disabled = true;
     //   l.title= "请先选择所属类别";
     //   l.alt = "请先选择所属类别";
    //}
</script>

<script language="javascript">
    function chk_select() {
        for (i = 0; i < document.getElementsByClassName("u-chk-th").length; i++) {
            if (document.getElementsByTagName("table")[0].getElementsByTagName("th")[0].getElementsByTagName("input")[0].checked) {
                document.getElementsByClassName("u-chk-th")[i].getElementsByTagName("input")[0].checked = true;
            } else {
                document.getElementsByClassName("u-chk-th")[i].getElementsByTagName("input")[0].checked = false;
            }
        }
    }
    function chk_click() {
        tmp = 0;
        for (i = 0; i < document.getElementsByClassName("u-chk-th").length; i++) {
            if (document.getElementsByClassName("u-chk-th")[i].getElementsByTagName("input")[0].checked) {
                tmp++
            }
        }
        if (tmp == document.getElementsByClassName("u-chk-th").length) {
            document.getElementsByTagName("table")[0].getElementsByTagName("th")[0].getElementsByTagName("input")[0].checked = true;
        }
        else {
            if (tmp == 0) {
                document.getElementsByTagName("table")[0].getElementsByTagName("th")[0].getElementsByTagName("input")[0].checked = false;
            }
        }
    }
    document.getElementsByTagName("table")[0].getElementsByTagName("th")[0].onclick = chk_select;
    document.getElementsByTagName("table")[0].getElementsByTagName("th")[0].innerHTML = "<input type='checkbox' name='fly-chk' id='fly-chk'>";//"选中/取消选中";
    for (j = 0; j < document.getElementsByClassName("u-chk-th").length; j++) {
        document.getElementsByClassName("u-chk-th")[j].getElementsByTagName("input")[0].onclick = chk_click;
    }

</script>

<script language="javascript">
        var pikaday1 = new Pikaday({
            field: document.getElementById('scheduledDate'),
            firstDay: 1,
            minDate: new Date('2016-01-01'),
            maxDate: new Date('2026-12-31'),
            yearRange: [2005,2025],
            onSelect: function () { },
            onOpen: function () {
            }
        });
</script>